package com.zj.web.controller;

import com.zj.service.CategoryService;
import com.zj.web.bean.CategoryDTO;
import com.zj.web.bean.ResponseResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/auth/category")
@RefreshScope //开启动态刷新
@Tag(name = "分类控制器",description = "提供对分类资源的添加，查询并显示等操作")
public class AuthCategoryController {
    @Autowired
    private CategoryService categoryService;
    /**
     * 前台：根据状态查询分类列表
     * */
    @GetMapping("/getCategoriesByStatus/{categoryStatus}")
    public ResponseEntity<ResponseResult> getCategoriesByStatus(@PathVariable("categoryStatus") Integer categoryStatus){
        List<CategoryDTO> categoryList = categoryService.getCategories(categoryStatus);
        return ResponseEntity.ok(ResponseResult.ok().setdata(categoryList));
    }
    /**
     * 前台：根据分类id查询分类信息
     * */
    @GetMapping("/getCategoryById/{categoryId}")
    public ResponseEntity<ResponseResult> getCategoryById(@PathVariable("categoryId") Long categoryId){
        CategoryDTO categoryDTO = categoryService.getCategoryById(categoryId);
        return ResponseEntity.ok(ResponseResult.ok().setdata(categoryDTO));
    }
}
